<template>
  <div class="equipment">
    <el-form class="top">
        <el-form-item>
          <el-input
            placeholder="请填科室名称"
            v-model="departmentname"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">搜索</el-button>
          <el-button type="primary" @click="addEquipment(true, 'row', 'add')"
            >添加科室</el-button
          >
        </el-form-item>
    </el-form>
    <edialog
      v-if="edialog"
      :edialog="edialog"
      :list="list"
      :Type="type"
    ></edialog>
    <v-table :header="header" :tableList="tableData"></v-table>
    <v-pagination :total="total" @currentPage="currentPage"></v-pagination>
  </div>
</template>

<script>
import vTable from "../../components/Table/index";
import vPagination from "@/components/pagination/index";
import edialog from "./dialog/edialog";
export default {
  inject: ["reload"],
  data() {
    return {
      type: "",
      department: "",
      departmentlist: [],
      header: [
        { prop: "id", label: "序号" },
        {
          prop: "departmentName",
          label: "科室",
        },
        { prop: "updateTime", label: "最新更新时间" },
        {
          label: "操作",
          render: (h, data) => {
            return (
              <div>
                <el-button
                  type="text"
                  onClick={() => {
                    this.reviseClick(true, data.row);
                  }}
                >
                  修改
                </el-button>
                <el-divider direction="vertical"></el-divider>
                <el-button
                  type="text"
                  onClick={() => {
                    this.delClick(data.row);
                  }}
                >
                  删除
                </el-button>
              </div>
            );
          },
        },
      ],
      tableData: [
        {
          Number_eq: "123456789",
          departmentName: "妇产科",
          equipmentCode: "",
        },
      ],
      total: 0,
      edialog: false,
      departmentname: "",
    };
  },
  mounted() {
    // this.$nextTick(() => {

    // });
    let data = {
      current: 1,
      departmentName: "",
    };
    this.getDepartmentAll(data);
  },
  methods: {
    //添加设备按钮
    addEquipment(status, row, type) {
      this.edialog = status;
      this.type = type;
    },
    // 删除一行数据
    delClick(data) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api
            .deleteDepartment(data)
            .then((res) => {
              this.$message.success(res.message);
              this.reload();
            })
            .catch((err) => {
              this.$message.error(err.message);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    reviseClick(status, row) {
      this.$options.methods.addEquipment.bind(this)(status);
      this.addEquipment(status, row, "edit");
      this.list = row;
    },
    //当前页
    currentPage(val) {
      console.log(val);
      let data = {
        current: val,
        size: 10,
        departmentName: "",
      };
      this.getDepartmentAll(data);
    },
    // 查看全部科室信息
    getDepartmentAll(data) {
      this.$api
        .getDepartmentAll(data)
        .then((res) => {
          this.tableData = res.data.data;
          this.total = res.total;
        })
        .catch((err) => {
          if (err.code == 6000) {
            this.tableData = [];
            this.total = 0;
          }
        });
    },
    // 搜索框
    search() {
      // console.log(1111);
      let data = {
        departmentName: this.departmentname,
        current: 1,
      };
      this.getDepartmentAll(data);
    },
  },
  components: {
    vTable,
    vPagination,
    edialog,
  },
};
</script>

<style lang="scss" scoped>
.equipment {
  height: 100%;
  background-color: #fff;
  padding: 19px 42px 0;
  .top {
    display: flex;
    justify-content: space-between;
  }
}
</style>